package StudentDao;

import Student.Student;

import java.util.ArrayList;

public class StudentDao implements StudentDaoInterface{
    ArrayList<Student> list = new ArrayList<>();

    public void zhuce(Student student) {
        list.add(student);
    }
    public void findAllStudent(){
        if (list.size()==0){
            System.out.println("数据不存在请注册后再查找");
        }else {
            System.out.println(list);
        }
    }
    public Student findStudent(){
        Student student = new Student();
        for (int i = 0; i < list.size(); i++) {
             student = list.get(i);
    }
        return student;
    }

    @Override
    public boolean updatePassWord(String name, String newPassWord) {
        boolean flag = false;
        for (int i = 0; i < list.size(); i++) {
            Student student =list.get(i);
            if (student.getName().equals(name)){
                student.setPassword(newPassWord);
               // Student students = new Student(name,newPassWord,student.getAge(),student.getSubject());
               // list.add(students);
               //list.remove(student);
               flag = true;
            }
        }
        return flag;
    }


    public boolean Exit(String name) {
        for (int i = 0; i < list.size(); i++) {
            Student student= list.get(i);
            if (student.getName().equals(name)){
                return false;
            }
        }
        return true;
        }
    }

